package com.x.dao.impl;

import com.x.dao.StudentDao;
import com.x.pojo.Student;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

import java.util.List;

/**
 * ClassName: StudentDaoImpl
 * Package: IntelliJ IDEA
 * Description:
 * Written by HanXu
 * Create 2024.09.02 22:03
 */
public class StudentDaoImpl implements StudentDao {

    private JdbcTemplate jdbcTemplate;

    //准备DI注入的set方法
    public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
        this.jdbcTemplate = jdbcTemplate;
    }

    @Override
    public List<Student> queryAll() {
        //jdbcTemplate进行数据库查询: ioc容器装配
        String sql = "select id, name, gender, age, class as classes from students ";
        List<Student> studentList = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(Student.class));
        System.out.println("StudentDao层: "+ studentList);

        return studentList;
    }
}
